package com.kedacom.demo.redis;

import org.springframework.util.StringUtils;

/**
 * 用户在当前线程中切换Redis连接的帮助类
 * @author luocanfeng
 * @date 2017年5月3日
 */
public class RedisConnectionFactorySwitcher {

	private static final ThreadLocal<String> connectionFactoryLookupKeyHolder = new ThreadLocal<String>();
	private static String DEFAULT_LOOKUP_KEY = "default";

	public static void setDefault() {
		connectionFactoryLookupKeyHolder.set(DEFAULT_LOOKUP_KEY);
	}

	public static void setLookupKey(String lookupKey) {
		connectionFactoryLookupKeyHolder.set(lookupKey);
	}

	public static String getLookupKey() {
		String lookupKey = connectionFactoryLookupKeyHolder.get();
		return StringUtils.isEmpty(lookupKey) ? DEFAULT_LOOKUP_KEY : lookupKey;
	}

}
